package org.dromara.system.cloud;


import cn.hutool.core.date.DateTime;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.SecureUtil;
import lombok.Data;
import org.dromara.system.domain.SysMiniAdmin;
import org.dromara.system.domain.SysTenant;

@Data
public class MiniAdmin extends MiniBase{


//    {"_id":"ef45322e66bca5b706f1c99f0fb38848",
//        "ADMIN_NAME":"admin2",
//        "ADMIN_PASSWORD":"e10adc3949ba59abbe56e057f20f883e",
//        "ADMIN_DESC":"超管2",
//        "ADMIN_TYPE":1,
//        "_pid":"workfit",
//        "ADMIN_ID":"20240814124023782",
//        "ADMIN_ADD_TIME":1723639223781,
//        "ADMIN_EDIT_TIME":1724662040214,
//        "ADMIN_ADD_IP":"120.229.54.11",
//        "ADMIN_EDIT_IP":"183.14.31.223",
//        "ADMIN_PHONE":"",
//        "ADMIN_STATUS":1,
//        "ADMIN_LOGIN_CNT":19,
//        "ADMIN_LOGIN_TIME":1724662040214,
//        "ADMIN_TOKEN":"kvukyri9ynnle91vq0yod3haybhewj4m",
//        "ADMIN_TOKEN_TIME":1724662040214,
//        "tenant_id":2.0}

    private String _id;


    private String ADMIN_DESC;
    private Integer ADMIN_TYPE;
    private String _pid;
    private String ADMIN_ID;
    private Long ADMIN_ADD_TIME;
    private Long ADMIN_EDIT_TIME;
    private String ADMIN_ADD_IP;
    private String ADMIN_EDIT_IP;
    private String ADMIN_PHONE;
    private Integer ADMIN_STATUS;
    private Integer ADMIN_LOGIN_CNT;
    private Long ADMIN_LOGIN_TIME;
    private String ADMIN_TOKEN;
    private Long ADMIN_TOKEN_TIME;

    private String ADMIN_NAME;
    private String ADMIN_PASSWORD;
    private Integer tenant_id;
    /**
     * 租户状态（0正常 1停用）
     */
    private String status;

    public static MiniAdmin build(SysTenant sysTenant) {
        MiniAdmin miniAdmin = new MiniAdmin();
        miniAdmin.setADMIN_DESC("");
        miniAdmin.setADMIN_TYPE(1);

        //获取当前时间戳
        miniAdmin.setADMIN_ADD_TIME(System.currentTimeMillis());
        miniAdmin.setADMIN_EDIT_TIME(System.currentTimeMillis());
        miniAdmin.setADMIN_ADD_IP("");
        miniAdmin.setADMIN_EDIT_IP("");
        miniAdmin.setADMIN_PHONE("");
        miniAdmin.setADMIN_STATUS(1);
        miniAdmin.setADMIN_LOGIN_CNT(0);
        miniAdmin.setADMIN_LOGIN_TIME(System.currentTimeMillis());
        miniAdmin.setADMIN_TOKEN("");
        miniAdmin.setADMIN_TOKEN_TIME(System.currentTimeMillis());

        Integer adminTenantId = Integer.parseInt(sysTenant.getTenantId());
        //租户表id对应admin_id,id对应tenant_id
        miniAdmin.setADMIN_ID(adminTenantId.toString());
        miniAdmin.setADMIN_NAME(sysTenant.getAdminName());
        miniAdmin.setADMIN_PASSWORD(SecureUtil.md5(sysTenant.getAdminPassword()));
        miniAdmin.setTenant_id(adminTenantId);

        return miniAdmin;
    }
}

